/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bizintelapps.zaetoon.service;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author atefahmed
 */
public class PasswordValidator {

    private Pattern pattern;
    private Matcher matcher;
    private static final String PASSWORD_PATTERN =
            "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%=]).{6,20})";
    private static final String EMAIL_PATTERN =
            "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";

    public PasswordValidator() {
        pattern = Pattern.compile(PASSWORD_PATTERN);
    }

    public boolean validate(final String password) {
        matcher = pattern.matcher(password);
        return matcher.matches();
    }

    public boolean isEmailValid(final String email) {
        CharSequence inputStr = email;
        boolean isValid = false;

        Pattern emailPattern = Pattern.compile(EMAIL_PATTERN, Pattern.CASE_INSENSITIVE);
        Matcher emailMatcher = emailPattern.matcher(inputStr);

        if(emailMatcher.matches()){
            isValid = true;
        }

        return isValid;
    }
}
